/**
 * @file phone.h
 *
 */
#ifndef PHONE_H
#define PHONE_H

#ifdef __cplusplus
extern "C" {
#endif

/*********************
 *      INCLUDES
 *********************/

#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lvgl.h"
#include "lv_watch_conf.h"
#else
#include "../../../lvgl/lvgl.h"
#include "../../../lv_watch_conf.h"
#endif

#if USE_LV_WATCH_PHONE != 0

/*********************
 *      DEFINES
 *********************/
#define PHONE_TEST  0    //for test code
#define PHONE_ANONYMOUS_NUMBER "anonymous"

/**********************
 *      TYPEDEFS
 **********************/
typedef enum {
    PHONE_UI_RING = 0,
    PHONE_UI_DIALING,
    PHONE_UI_CONNECTED,
} phone_ui_t;

typedef struct {
    MMI_MODEM_CALL_STATE state;
    int32_t              index;                    /* Connection Index for use with, eg, AT+CHLD */
    bool                 is_mt;                    /* true if MT call */
    bool                 ring_off;                 /* true if ring off by user */
    bool                 ring_off_timeout;         /* true if ring off timeout */
    bool                 waiting_response_dial;
#if 0
    bool                 buffer_alarm;
#endif
#define RING_OFF_TIMER_LEN    5000
    TIMER_ID             ring_off_timer_id;        /* ring off timer */
#define CEER_TIMER_LEN        1000
    TIMER_ID             ceer_timer_id;            /* wait for +CEER timer */
#define REDIAL_TIMER_LEN      2000
    TIMER_ID             redial_timer_id;          /* redial timer */
#define REDIAL_MAX_CNT        3
    uint8_t              redial_cnt;
    char                 number[NV_CONTACTS_MAX_NUMBER_LEN];   /* phone number */
    char                 name[NV_CONTACTS_MAX_NAME_LEN];       /* contact name */
    const char * img_src;
    const char * img_src_small;
    uint8_t              speaker_volume;           /* speaker volume during call procedure */
    MMI_MODEM_CALL_SERVICE_TYPE service_type;
} phone_call_params_t;

typedef struct {
    lv_watch_obj_ext_t lv_watch_obj;
    /*New data for this type */
    lv_obj_t * phone_status_label;
    lv_obj_t * phone_status_label1;
    lv_obj_t * phone_wait_label;
    lv_obj_t * phone_animation_obj;
    uint32_t connect_start_time;
    uint32_t connect_start_time2;
    phone_ui_t phone_ui_id;
    lv_obj_t * num_label;
    lv_obj_t * num_label1;
    lv_obj_t * num_label2;
    lv_obj_t * btn_cont;
    lv_obj_t * connect_img;
    lv_obj_t * callwait_img;
    bool ring_off_anim_create;
} lv_phone_obj_ext_t;

/**********************
 * GLOBAL PROTOTYPES
 **********************/
void phone_voice_call_req(char *number);
void phone_init(void);
uint8_t phone_get_call_speaker_volume(void);
bool phone_is_monitor_on(void);
uint8_t phone_get_call_volume(void);
#if 0
void phone_alarm_ind(void);
#endif
MMI_MODEM_CALL_STATE phone_get_call_state(void);
bool watch_phone_suspend_check(void);
void ring_hook_action(lv_obj_t * btn, lv_event_t e);
lv_obj_t * phone_get_activity_obj(void);
void phone_audio_ctrl_callback(AUDIO_CTRL_PRIORITY priority);
lv_phone_obj_ext_t * phone_get_ext(void);
void phone_cleanup(void);
#if USE_LV_BLUETOOTH
void watch_bt_sco_set_call_type(int8_t type);
#endif
/**********************
 *      MACROS
 **********************/

#endif /*USE_LV_WATCH_PHONE*/

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /*PHONE_H*/
